//
//  PChargeEBarChartView.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2023/10/13.
//  参考:https://www.cnblogs.com/wangkejia/archive/2021/11/01/15494841.html

#import "RHChargeBarChartView.h"
#import "KBValueFormatter.h"
#import "DevChartModel.h"
#import "DeviceChartFieldModel.h"
#import "DeviceChartItemView.h"
#import "NSString+LenWid.h"
#import "QMUILabel+LHAdd.h"

@interface RHChargeBarChartView()<ChartAxisValueFormatter,ChartValueFormatter>
@property (nonatomic ,copy) NSArray *colorList;

@property (nonatomic, strong)BarChartView *barChartView;

//前一天
@property (nonatomic ,strong) QMUIButton *l_btn;
//后一天
@property (nonatomic ,strong) QMUIButton *r_btn;
//日期
@property (nonatomic ,strong) QMUIButton *timeBtn;

//左边Y轴单位
@property (nonatomic, strong) QMUILabel *leftUnitLab;
//右边Y轴单位
@property (nonatomic, strong) QMUILabel *rightUnitLab;

//年,月,日
@property (nonatomic ,assign) NSInteger type;

@property (nonatomic, assign) NSInteger selectIndex;

@property (nonatomic, strong) UIView *scrollBgView;

@property (nonatomic, strong) UIScrollView *scroll;

@property (nonatomic, strong) UIView *contentView;

@property (nonatomic, strong) NSMutableArray *itemsArray;

@property (nonatomic, strong) NSMutableArray *unitArr;
@end

@implementation RHChargeBarChartView

- (instancetype)initWithFrame:(CGRect)frame type:(NSInteger)type{
    self = [super initWithFrame:frame];
    if (self) {
        self.colorList = @[@"#46ECA6",@"#678EF2",@"#E76262",@"#77E4D1",@"#F9CF4A"];
        self.type = type;
        [self setupUI];
        
    }
    return self;
}

- (void)setChartModel:(DevChartModel *)chartModel{
   
    _chartModel = chartModel;
    self.selectIndex = _chartModel.timeType;
    [self setChartData];
    NSString *timeStr;
    if (_chartModel.timeType == TimeType_Day) {
        NSDate *date = [NSDate dateWithTimeIntervalSince1970:[_chartModel.curTime integerValue]];
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateStyle:NSDateFormatterMediumStyle];
        [formatter setTimeStyle:NSDateFormatterShortStyle];
        [formatter setDateFormat:@"YYYY-MM-dd"];
        NSString *dateTime = [formatter stringFromDate:date];
        timeStr = dateTime;
        [_r_btn setEnabled:[date isToday]?NO:YES];
    }else if (_chartModel.timeType == TimeType_Month) {
        NSDate *date = [NSDate dateWithTimeIntervalSince1970:[_chartModel.curTime integerValue]];
        timeStr = [NSString stringWithFormat:@"%02ld-%02ld",[date year],[date month]];
        [_r_btn setEnabled:[[NSDate date] monthsLaterThan:date]?YES:NO];
    }else if (_chartModel.timeType == TimeType_Year){
        NSDate *date = [NSDate dateWithTimeIntervalSince1970:[_chartModel.curTime integerValue]];
        timeStr = [NSString stringWithFormat:@"%ld",[date year]];
        [_r_btn setEnabled:[[NSDate date] yearsLaterThan:date]?YES:NO];
    }else{
        timeStr = @"";
    }

    [self.timeBtn setTitle:ValidStr(timeStr)?timeStr:@"" forState:UIControlStateNormal];
    
    __block CGFloat total_width = 0;
    kWeakSelf;
    [self.itemsArray enumerateObjectsUsingBlock:^(DeviceChartItemView  *_Nonnull itemView, NSUInteger idx, BOOL * _Nonnull stop) {
        CGFloat item_width = 0;
        DeviceChartFieldModel *model;
        if (idx<self.chartModel.selectArray.count) {
            model = self.chartModel.selectArray[idx];
            model.colorStr = self.colorList[idx];
            [itemView setModel:model];
            NSAttributedString *attr = [[NSAttributedString alloc] initWithString:model.keyName];
            CGSize size = [itemView.conentLab getLableSizeWithAttStr:attr maxHeight:15];
            item_width = size.width+25;
            [itemView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.width.mas_equalTo(item_width);
            }];
            [itemView setHidden:NO];
            total_width = total_width+item_width+5;
        }else{
            [itemView setHidden:NO];
            [itemView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.width.mas_equalTo(0);
            }];
        }
        
        [self.scrollBgView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(MIN(self.frame.size.width,total_width+5));
        }];
    
        itemView.selectBlock = ^BOOL(DeviceChartFieldModel * _Nonnull model) {
            model.isShowLine = !model.isShowLine;
            [weakSelf.chartModel updateyAxisArray];
            [weakSelf setChartData];
            return YES;
        };
    }];

}

-(void)setChartData
{
    [self.barChartView clear];
    self.leftUnitLab.hidden = YES;
    //X轴要显示的数据
    self.barChartView.xAxis.valueFormatter = [[ChartIndexAxisValueFormatter alloc]initWithValues:self.chartModel.xTitlesArray];

    [self.unitArr removeAllObjects];
    kWeakSelf;
    __block CGFloat left_y_max = 0;
    __block CGFloat right_y_max = 0;
    NSMutableArray *dataSets = [[NSMutableArray alloc] init];
    [self.chartModel.selectArray enumerateObjectsUsingBlock:^(DeviceChartFieldModel  *_Nonnull model, NSUInteger idx, BOOL * _Nonnull stop) {
        if(model.dataArray.count == 0)return;
        if(model.isShowLine){
            BarChartDataSet *set = [weakSelf createDataSetWithModel:model linecolor:weakSelf.colorList[idx]];
            //单位
            if(![weakSelf.unitArr containsObject:model.unitName]){
                [weakSelf.unitArr addObject:ValidNullDataToString(model.unitName, @"--")];
            }
            //数据对应 左边Y轴 还是 右边Y轴
            if(weakSelf.unitArr.count<2){
                set.axisDependency = AxisDependencyLeft;
                left_y_max = MAX(model.value_max, left_y_max);
                self.leftUnitLab.text = model.unitName;
                self.leftUnitLab.hidden = NO;
            }else{
                //两个单位
                if([model.unitName isEqualToString:weakSelf.unitArr[0]]){
                    set.axisDependency = AxisDependencyLeft;
                    left_y_max = MAX(model.value_max, left_y_max);
                }else{
                    set.axisDependency = AxisDependencyRight;
                    right_y_max = MAX(model.value_max, right_y_max);
                    self.rightUnitLab.text = model.unitName;
                    self.rightUnitLab.hidden = NO;
                }
                
                self.barChartView.rightAxis.enabled = YES;
            }
            
            [dataSets addObject:set];
            
        }
        
    }];
    self.barChartView.leftAxis.axisMaximum = left_y_max + 9.9;
    self.barChartView.rightAxis.axisMaximum = right_y_max + 9.9;
    //没有数据的时候也展示
    if(left_y_max == 0)
    {
        left_y_max = 100;
    }
    if(right_y_max == 0){
        right_y_max = 100;
    }
    
    BarChartData *data = [[BarChartData alloc] initWithDataSets:dataSets];
    
    //每组的间距
    float groupSpace = 0.6;
    //每条柱子之间的间距
    float barSpace = dataSets.count==0? 0.1 : 0.1/dataSets.count;
    //每组的宽度
    float barWidth = dataSets.count==0? 0.3 : 0.3/dataSets.count;
    
    data.barWidth = barWidth;
  
    // 设置X轴数据
    _barChartView.data = data;
    CGFloat granularity = (barWidth + barSpace) * dataSets.count + groupSpace;
    NSLog(@"---->每组的间隔:%f",granularity);
    //（barWidth + barSpace）* 组内个数 + groupSpace = 每个"组"的间隔 granularity,这个关系对齐问题
    _barChartView.xAxis.granularity = granularity;
    
    _barChartView.xAxis.axisMaximum = -0.5 + [data groupWidthWithGroupSpace:groupSpace barSpace: barSpace] * self.chartModel.xTitlesArray.count;
    [_barChartView.xAxis setLabelCount:self.chartModel.xTitlesArray.count];
    [data groupBarsFromX: -0.5 groupSpace: groupSpace barSpace: barSpace];
    //设置可见数量
    [_barChartView setVisibleXRangeMaximum:8];
    
    //这里可以调用一个加载动画即1s出来一个绘制点
//    [self.lineChartView animateWithXAxisDuration:0.2f];
   
    //通知data去更新
    [self.barChartView.data notifyDataChanged];
    //通知图表去更新
    [self.barChartView notifyDataSetChanged];
}

#pragma mark ----- 创建曲线
-(BarChartDataSet*)createDataSetWithModel:(DeviceChartFieldModel*)model linecolor:(NSString*)colorStr;
{
    NSMutableArray *entryArr = [[NSMutableArray alloc]init];
    
    [self.chartModel.xTitlesArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        BarChartDataEntry *entry = [[BarChartDataEntry alloc] initWithX:idx y:[model.dataArray[idx] floatValue]];
        [entryArr addObject:entry];
    }];
    

    BarChartDataSet *set = [[BarChartDataSet alloc] initWithEntries:entryArr label:model.keyName];
    //是否在柱形图上面显示数值
    set.drawValuesEnabled = NO;
    set.valueFormatter = self;
    [set setColor:kCOLOR_HEX(colorStr)];//折线颜色
    set.highlightEnabled = NO;

    return set;
}

-(void)setupUI
{
    UIView *itemBgView = [[UIView alloc] init];
    [itemBgView setBackgroundColor:UIColor.whiteColor];
    [self addSubview:itemBgView];
    
    kWeakSelf;
    UIView *line = kView;
    line.backgroundColor = CMainColorGreen;
    [self addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.offset(2);
    }];
    //全屏
    QMUIButton *full_btn = [QMUIButton buttonWithType:UIButtonTypeCustom];
    [full_btn setImagePosition:QMUIButtonImagePositionRight];
    [full_btn setImage:[UIImage imageNamed:@"full_screen"] forState:UIControlStateNormal];
    [full_btn setTitle:@"" forState:UIControlStateNormal];
    [self addSubview:full_btn];
    
    NSArray *titles = @[@"Month",@"Year",@"Total"];
    if (self.type == 0) {
        titles = @[@"Month",@"Year",@"Total"];
    }else if (self.type == 1){
        titles = @[@"Day",@"Month"];
    }else if (self.type == 2){
        titles = @[@"Day"];
    }
    __block QMUIButton *lastbtn;
   
    [titles enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        //    NSAttributedString *attr = [[NSAttributedString alloc] initWithString:_nameStr];
        //CGSize size = [self.nameLab getLableSizeWithAttStr:attr maxHeight:18];
        QMUIButton *btn = [QMUIButton buttonWithType:UIButtonTypeCustom];
        [btn setBackgroundColor:UIColor.whiteColor];
        [btn setTitle:obj forState:UIControlStateNormal];
        [btn setTitleColor:FontColor(@"#000000") forState:UIControlStateNormal];
        [btn.titleLabel setFont:[UIFont systemFontOfSize:13]];
        CGFloat width = [obj getStringWidthFont:btn.titleLabel.font limitHeight:200];
        [itemBgView addSubview:btn];
        
        if(idx == 0){
            [line mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.top.equalTo(btn.mas_bottom).offset(0);
                    make.centerX.equalTo(btn);
                    make.width.equalTo(btn).offset(-10);
            }];
        }
        
        [[btn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            [weakSelf btnAction:idx];
            [line mas_remakeConstraints:^(MASConstraintMaker *make) {
                    make.top.equalTo(x.mas_bottom).offset(0);
                    make.centerX.equalTo(x);
                    make.width.equalTo(x).offset(-10);
                    make.height.offset(2);
            }];
            
        }];
        
        
        [RACObserve(weakSelf, selectIndex) subscribeNext:^(id  _Nullable x) {
            NSInteger index = [x integerValue];
            
            if (index == idx) {
                [btn.titleLabel setFont:[UIFont boldSystemFontOfSize:12]];
                [btn setTitleColor:kCOLOR_HEX(@"323233") forState:UIControlStateNormal];
            }else{
                [btn.titleLabel setFont:[UIFont systemFontOfSize:12]];
                [btn setTitleColor:kCOLOR_HEX(@"969799") forState:UIControlStateNormal];
            }
            
        }];
        
        if (!lastbtn) {
            [btn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_offset(0.5);
                make.top.mas_offset(0.5);
                make.bottom.mas_offset(-0.5);
                make.width.mas_equalTo(width+10);
                make.height.offset(25);
            }];
        }else{
            [btn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(lastbtn.mas_right).offset(2);
                make.top.mas_offset(0.5);
                make.bottom.mas_offset(-0.5);
                make.width.mas_equalTo(width+10);
                make.height.offset(25);
            }];
        }
        lastbtn = btn;
    }];
    
    [lastbtn mas_updateConstraints:^(MASConstraintMaker *make) {
        make.right.mas_offset(-0.5);
    }];
    
    [itemBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_offset(20);
    }];
    
    QMUIButton *dateBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
    [dateBtn setBackgroundColor:UIColor.whiteColor];
    [dateBtn setTitle:@"2023-08-09" forState:UIControlStateNormal];
    [dateBtn setImagePosition:QMUIButtonImagePositionRight];
    dateBtn.spacingBetweenImageAndTitle = 5;
    [dateBtn setTitleColor:FontColor(@"#000000") forState:UIControlStateNormal];
    [dateBtn.titleLabel setFont:[UIFont systemFontOfSize:12]];
    [self addSubview:dateBtn];
    self.timeBtn = dateBtn;
    
    _l_btn = [QMUIButton buttonWithType:UIButtonTypeCustom];
    [_l_btn setImagePosition:QMUIButtonImagePositionRight];
    [_l_btn setImage:[UIImage imageNamed:@"day_left"] forState:UIControlStateNormal];
    [self addSubview:_l_btn];
    
    _r_btn = [QMUIButton buttonWithType:UIButtonTypeCustom];
    [_r_btn setImagePosition:QMUIButtonImagePositionRight];
    [_r_btn setImage:[UIImage imageNamed:@"day_right"] forState:UIControlStateNormal];
    [self addSubview:_r_btn];


    
    [full_btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(50, 40));
        make.right.mas_offset(-5);
        make.centerY.equalTo(itemBgView);
    }];
    
    [dateBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(full_btn.mas_bottom).offset(5);
        make.size.mas_equalTo(CGSizeMake(80, 30));
        make.centerX.mas_offset(0);
    }];
    
    [_l_btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(50, 30));
        make.centerY.equalTo(dateBtn);
        make.right.equalTo(dateBtn.mas_left);
    }];

    [_r_btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(50, 30));
        make.centerY.equalTo(dateBtn);
        make.left.equalTo(dateBtn.mas_right);
    }];
    
   
    
    [[full_btn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        [weakSelf fullAction];
    }];
    
    [[_l_btn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {//日期往前
        if (weakSelf.subTimeBlock) {
            weakSelf.subTimeBlock();
        }
    }];
    
    [[_r_btn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {//日期往后
        if (weakSelf.addTimeBlock) {
            weakSelf.addTimeBlock();
        }
    }];
    
    [[dateBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        if (weakSelf.changeTimeBlock) {
            weakSelf.changeTimeBlock();
        }
    }];
    
    
    
    //---------------- 图表
    _barChartView = [[BarChartView alloc] init];
    _barChartView.backgroundColor = [UIColor whiteColor];
    _barChartView.noDataText = @"没有数据";
    _barChartView.frame = CGRectMake(0, 0, 300, 200);
    _barChartView.dragEnabled = YES;
    _barChartView.pinchZoomEnabled = NO;   //捏合手势
    _barChartView.doubleTapToZoomEnabled = NO; //双击手势
    
    _barChartView.legend.enabled = YES;
    _barChartView.chartDescription.enabled = YES;
    _barChartView.extraTopOffset = 10;//图表边距
    _barChartView.extraLeftOffset = 10;
    _barChartView.extraRightOffset = 20;
    _barChartView.extraBottomOffset = 10;
    
    _barChartView.legend.enabled = NO;//是否显示说明图标
    _barChartView.legend.form = ChartLegendFormSquare;//说明图例的样式  --指导价走势
    _barChartView.legend.formSize = 8;//图例大小（头部）
    _barChartView.legend.formToTextSpace = 5;//图例与文字的距离
    _barChartView.legend.yOffset = 10;//图例与底部的距离
    _barChartView.legend.xOffset = 60;//图例与左边的距离
    _barChartView.legend.xEntrySpace = 50;//图例与图例之间的距离
    _barChartView.legend.stackSpace = 20;
    
    //X 轴
    ChartXAxis *xAxis = _barChartView.xAxis;
    xAxis.labelPosition = XAxisLabelPositionBottom;
    xAxis.labelFont = [UIFont systemFontOfSize:10.f];
    xAxis.labelWidth = 10;
    xAxis.gridLineDashPhase = 0.f;
    //不绘制网格线
    xAxis.drawGridLinesEnabled = NO;
    xAxis.axisMinimum = -0.5;
    xAxis.labelRotationAngle = 0;
    //设置虚线样式的网格线
    xAxis.gridLineDashLengths = @[@0.f, @0.f];
    //x轴标签间隔尺寸
//        xAxis.granularity = 1;
    //设置label间隔，若设置为1，每个柱形下面都会显示label
    xAxis.spaceMin = 1;
    
    //Y轴
    _barChartView.rightAxis.enabled = NO;//不绘制右边轴
    ChartYAxis *leftAxis = _barChartView.leftAxis;
//        leftAxis.axisMaximum = 100.0;
    leftAxis.axisMinimum = 0.0;
    leftAxis.axisLineWidth = 0;
    //设置虚线样式的网格线
    leftAxis.gridLineDashLengths = @[@3.f, @3.f];
    leftAxis.valueFormatter = self;
    [self addSubview:_barChartView];
    
    //添加单位
    QMUILabel *leftUnitLab = [[QMUILabel alloc]init];
    leftUnitLab.textColor = UIColor.lightGrayColor;
    leftUnitLab.font = [UIFont systemFontOfSize:13];
    [self addSubview:leftUnitLab];
    self.leftUnitLab = leftUnitLab;
    
    [leftUnitLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.barChartView).offset(5);
        make.bottom.equalTo(weakSelf.barChartView.mas_top).offset(0);
    }];

    
    [_barChartView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_offset(0);
        make.top.equalTo(dateBtn.mas_bottom).offset(20);
        make.height.offset(kUI_WINDOW_W*0.6);
       
    }];
    
    
    //下面的曲线标签按钮
    _scrollBgView = [[UIView alloc] init];
    [_scrollBgView setBackgroundColor:UIColor.orangeColor];
    [self addSubview:_scrollBgView];
    
    _scroll = [[UIScrollView alloc] init];
    [_scroll setShowsHorizontalScrollIndicator:NO];
    _scroll.backgroundColor = [UIColor whiteColor];
    [_scrollBgView addSubview:_scroll];
    
    _contentView = [[UIView alloc] init];
    _contentView.backgroundColor = [UIColor whiteColor];
    [_scroll addSubview:_contentView];
    
    __block DeviceChartItemView *lastItem;
    __block CGFloat width = 5;
    [self.colorList enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        DeviceChartItemView *itemView = [[DeviceChartItemView alloc] init];
        [itemView.markLab.layer setBorderColor:FontColor(obj).CGColor];
//        [itemView shadow:UIColor.blackColor opacity:0.1 radius:5 offset:CGSizeMake(0, 1)];
        [_contentView addSubview:itemView];
        [self.itemsArray addObject:itemView];

        if (!lastItem) {
            [itemView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_offset(width);
                make.top.mas_offset(5);
                make.centerY.mas_offset(0);
                make.height.mas_equalTo(20);
                make.width.mas_equalTo(0);
            }];
            width = width;
        }else{
            [itemView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(lastItem.mas_right).offset(5);
                make.top.mas_offset(5);
                make.centerY.mas_offset(0);
                make.height.mas_equalTo(20);
                make.width.mas_equalTo(0);
            }];
            width = width+5;
        }
        lastItem = itemView;
    }];
    
    [lastItem mas_updateConstraints:^(MASConstraintMaker *make) {
        make.right.mas_offset(0);
    }];
    
    
    [_scrollBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_offset(0);
        make.top.equalTo(weakSelf.barChartView.mas_bottom).offset(0);
        make.bottom.mas_offset(-10);
        make.height.mas_equalTo(30);
        make.width.mas_equalTo(MIN(self.frame.size.width,width));
    }];
    
    
    [_scroll mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsZero);
    }];
    
    [_contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsZero);
        make.width.greaterThanOrEqualTo(@0.f);//此处保证容器View高度的动态变化 大于等于0.f的高度
    }];
}
#pragma mark ------ Actions ------
- (void)fullAction{
    if (self.fullChartBlock) {
        self.fullChartBlock();
    }
}

- (void)btnAction:(NSInteger)index{
    if (self.selectTopToolBlock) {
        self.selectTopToolBlock(index);
    }
    
    if (index == -1) {//自定义参数设置
        return;
    }
    
    self.selectIndex = index;
    NSLog(@"---->选择的下标:%d",index);
    if (self.selectIndex == 1) {//Day
        
    }
    
    if (self.selectIndex == 2) {//Month
        
    }
    
    if (self.selectIndex == 3) {//Year
        
    }
    
    if (self.selectIndex == 4) {//Total
        
    }
}


#pragma mark - 折线值
- (NSString *)stringForValue:(double)value entry:(ChartDataEntry *)entry dataSetIndex:(NSInteger)dataSetIndex viewPortHandler:(ChartViewPortHandler *)viewPortHandler {
    
    return [NSString stringWithFormat:@"%.0f", value];
}
 
#pragma mark - y轴值
- (NSString *)stringForValue:(double)value axis:(ChartAxisBase *)axis {
   
    return [NSString stringWithFormat:@"%.0f", value];
}



#pragma mark 图表中数值被选中
-(void)chartValueSelected:(ChartViewBase *)chartView entry:(ChartDataEntry *)entry highlight:(ChartHighlight *)highlight{
    
}

#pragma mark 图表中的空白区域被选中
-(void)chartValueNothingSelected:(ChartViewBase *)chartView{
}

#pragma mark 图表被缩放
-(void)chartScaled:(ChartViewBase *)chartView scaleX:(CGFloat)scaleX scaleY:(CGFloat)scaleY{
}

#pragma mark 图表被移动
-(void)chartTranslated:(ChartViewBase *)chartView dX:(CGFloat)dX dY:(CGFloat)dY{

}


#pragma mark ------ lazy load
- (NSMutableArray *)itemsArray{
    if (!_itemsArray) {
        _itemsArray = [NSMutableArray array];
    }
    return _itemsArray;
}


-(NSMutableArray *)unitArr
{
    if(!_unitArr)
    {
        _unitArr = [NSMutableArray array];
    }
    return _unitArr;;
}

@end
